using System.Reflection;
using PhoneCore.Framework.IoC.Interception.Proxies;
namespace SecureBox.UI.Infrastructure.Data
{
    public class DataContextServiceProxy : ProxyBase, SecureBox.UI.Infrastructure.Data.IDataContextService
    {
        /*public void add_OnChanged(System.EventHandler<System.EventArgs> value){var methodInvocation = BuildMethodInvocation(MethodBase.GetCurrentMethod()
        ,value);RunBehaviors(methodInvocation)
        ;}

        public void remove_OnChanged(System.EventHandler<System.EventArgs> value){var methodInvocation = BuildMethodInvocation(MethodBase.GetCurrentMethod()
        ,value);RunBehaviors(methodInvocation)
        ;}*/

        public void Delete()
        {
            var methodInvocation = BuildMethodInvocation(MethodBase.GetCurrentMethod());
            RunBehaviors(methodInvocation);
        }

        public void Commit()
        {
            var methodInvocation = BuildMethodInvocation(MethodBase.GetCurrentMethod()); 
            RunBehaviors(methodInvocation);
        }

        public SecureBox.UI.Infrastructure.Model.IRepository<SecureBox.UI.Infrastructure.Model.Template> Templates
        {
            get
            {
                return RunBehaviors(BuildMethodInvocation(MethodBase.GetCurrentMethod()))
                    .GetReturnValue<SecureBox.UI.Infrastructure.Model.IRepository<SecureBox.UI.Infrastructure.Model.Template>>();
            }
        }

        public SecureBox.UI.Infrastructure.Model.IRepository<SecureBox.UI.Infrastructure.Model.Record> Records
        {
            get
            {
                return RunBehaviors(BuildMethodInvocation(MethodBase.GetCurrentMethod()))
                    .GetReturnValue<SecureBox.UI.Infrastructure.Model.IRepository<SecureBox.UI.Infrastructure.Model.Record>>();
            }
        }

        public SecureBox.UI.Infrastructure.Model.IRepository<SecureBox.UI.Infrastructure.Model.Keyword> Keywords
        {
            get
            {
                return RunBehaviors(BuildMethodInvocation(MethodBase.GetCurrentMethod()))
                    .GetReturnValue<SecureBox.UI.Infrastructure.Model.IRepository<SecureBox.UI.Infrastructure.Model.Keyword>>();
            }
        }

        public SecureBox.UI.Infrastructure.Model.IRepository<SecureBox.UI.Infrastructure.Model.Property> Properties
        {
            get
            {
                return RunBehaviors(BuildMethodInvocation(MethodBase.GetCurrentMethod()))
                    .GetReturnValue<SecureBox.UI.Infrastructure.Model.IRepository<SecureBox.UI.Infrastructure.Model.Property>>();
            }
        }

        public event System.EventHandler<System.EventArgs> OnChanged
        {
            add
            {
                lock (Instance)
                {
                    (Instance as IDataContextService).OnChanged += value;
                }
            }
            remove
            {
                lock (Instance)
                {
                    (Instance as IDataContextService).OnChanged -= value;
                }
            }
        }

        public void Dispose()
        {
            var methodInvocation = BuildMethodInvocation(MethodBase.GetCurrentMethod());
            RunBehaviors(methodInvocation);
        }

    }
}
